package arpc

import (
	"os"

	"github.com/zeromicro/go-zero/core/conf"
	"github.com/zeromicro/go-zero/core/logx"
	"github.com/zeromicro/go-zero/core/stores/redis"
	"github.com/zeromicro/go-zero/rest"
)

type (
	RestConf  = rest.RestConf
	LogConf   = logx.LogConf
	RedisConf = redis.RedisConf
)

type CommonConf struct {
	ClusterId  string `json:",default=test-cluster"`
	InstanceId string `json:",default=test-instance"`
	AuthKey    string `json:",optional"`
}

func FillDefault(v any) error {
	return conf.FillDefault(v)
}

func MustLoad(path string, v any) {
	conf.MustLoad(path, v)
}

func (c *CommonConf) ReplaceEnv() {
	// ClusterId
	clusterId := os.Getenv("ClusterId")
	if clusterId != "" {
		c.ClusterId = clusterId
	}

	// InstanceId
	instanceId := os.Getenv("InstanceId")
	if instanceId != "" {
		c.InstanceId = instanceId
	}

	// AuthKey
	authkey := os.Getenv("AuthKey")
	if authkey != "" {
		c.AuthKey = authkey
	}
}
